/************************************************************
 * Copyright (C), 2022-2030, dina. Co., Ltd.
 * FileName:        my_switch_button.h
 * Author:          Dan Yin
 * Date:            2023-01-17
 * Description:     customer switch button
 * Version:         1.0.0.0
 **********************************************************/

#ifndef MY_SWITCH_BUTTON_H
#define MY_SWITCH_BUTTON_H

// add necessary includes here
#include <QWidget>
#include <QPropertyAnimation>
#include <QPainter>
#include <QPainterPath>
#include <QRadialGradient>
#include <QMouseEvent>
#include <QApplication>


class MySwitchButton : public QWidget
{
    Q_OBJECT
public:
    // declare properties in class
    Q_PROPERTY(QColor clrBackground MEMBER m_clrBackground)

    // The default constructor
    explicit MySwitchButton(QWidget *parent = nullptr);

    // The default destructor
    virtual ~MySwitchButton();

    // Get the value of switch button
    bool getSwitchValue();

    // Get the enable state of switch button
    bool getEnableState();

signals:
    // The enabling state of the switch changes
    void signalEnableStateChanged(bool bEnable);

    // The value of the switch changes
    void signalValueChanged(bool bOnOff);

public slots:
    // Set the value of switch button
    void setSwitchValue(bool bValue = false, bool bNotifyChanged = true);

    // Set the enable state of switch button
    void setEnableState(bool bEnable = true);

    // Set the values of animation period
    void setAnimationPeriod(int nPeriod);

    // Set the precise click mark of button embedded in switch
    void setPrecisionClick(bool bClickFlag);

    // Set wait model (You need to call "setSwitch" function before switching the value of the switch)
    void setWaitModel(bool bWaitModel);

    // Set the values of switch under wait model
    void setSwitchUnderWaitModel(bool bSwitchValue = false);

    // Sets the color of the embedded controls for the switch
    void setInnerButtonColor(QColor clrButton);

    // Set the background color in the ON state
    void setBackgroundColorON(QColor clrBackground);

    // Set the background color in the OFF state
    void setBackgroundColorOFF(QColor clrBackground);

    // Set the edge color of the embedded control
    void setEmbeddedEdgeColor(QColor clrEdge = Qt::transparent);

protected:
    void paintEvent(QPaintEvent *event);
    void resizeEvent(QResizeEvent *event);
    void mouseReleaseEvent(QMouseEvent *event);
    void enterEvent(QEvent *event);
    void leaveEvent(QEvent *event);

private:
    // Status of switch
    bool m_bValueOnOff = false;

    // Enable state of switch
    bool m_bEnableState = true;

    // Precise click mark of button embedded in switch
    bool m_bPrecisionClick = false;

    // Wait mode, the position of the button will change after clicking, but the color will not change unless the signal is received
    bool m_bWaitModelForSignal = false;

    // Mouse Hover Event
    bool m_bMouseHover = false;

    // The radian of the four corners of the rectangle
    int m_nBorderRadius = 8;

    // Color of switch
    QColor m_clrButton = Qt::white;
    QColor m_clrBackground = Qt::gray;
    QColor m_clrButtonEdge = Qt::transparent;

    // Inline button of switch
    QRectF m_recButton;

    // Animation period
    int m_nAnimationPeriod = 200;

    // Animation position of switch
    QPointF m_pntRightON;
    QPointF m_pntLeftOFF;

    // Background color of switch
    QColor m_clrBackgroundON = QColor(153, 194, 251, 255);
    QColor m_clrBackgroundOFF = Qt::darkGray;
};

#endif // MY_SWITCH_BUTTON_H
